package com.zzz.demo.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.UUID;

/**
 * @author ZZZ
 * @version 1.0
 * @date 2018/7/17 0017
 */
@EnableAsync
@Service
public class AsyncTask {

    @Async
    public void task1(){
//        System.out.println("任务1正在执行.............");
        System.out.println("f1 : " + Thread.currentThread().getName() + "   " + UUID.randomUUID().toString());
        try {
            Thread.sleep(new Random().nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Async
    public void task2(){
//        System.out.println("任务2正在执行.............");
        System.out.println("f2 : " + Thread.currentThread().getName() + "   " + UUID.randomUUID().toString());
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Async
    public void task3(){
//        System.out.println("任务3正在执行.............");
        System.out.println("f3 : " + Thread.currentThread().getName() + "   " + UUID.randomUUID().toString());
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
